#! python3
# -*- coding : utf-8 -*-

from ctypes import WinDLL, c_int
from pathlib import Path
import vim

dll_path = Path(vim.eval('g:gvimfullscreen_lib_path'))

def toggle(path=dll_path):
    if not isinstance(path, Path):
        path = Path(path)
    if not path.exists():
        return None
    try:
        dll = WinDLL(str(path))
        func = getattr(dll, 'ToggleFullScreen')
        func.restype = c_int
        func.argtypes = ()
        return func()
    except OSError as e:
        print(f"Path {path} failed with error `{e}`")
        path = Path(path).with_suffix('.x64.dll')
        if path.exists():
            toggle(path=path)
        return None
